package com.sol.mapreduce._6_writable_comparable_partition;

import com.sol.mapreduce.util.SysUtil;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/**
 * @author: lujie
 * @date: 2021/11/28 13:48
 *
 *
 **/
public class FlowDriver {
    public static final String CASE_NAME =  "6_writable_comparable_partition";
    public static void main(String[] args) throws Exception {
        //1 获取 job 对象
        //1 获取 job 对象
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);
        //2 关联本 Driver 类
        job.setJarByClass(FlowDriver.class);
        //3 关联 Mapper 和 Reducer
        job.setMapperClass(FlowMapper.class);
        job.setReducerClass(FlowReducer.class);
        //4 设置 Map 端输出数据的 KV 类型
        job.setMapOutputKeyClass(FlowBean.class);
        job.setMapOutputValueClass(Text.class);
        //5 设置程序最终输出的 KV 类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(FlowBean.class);
        job.setPartitionerClass(CustomPartitioner2.class);
        job.setNumReduceTasks(5);
        //6 设置输入输出路径
        FileInputFormat.setInputPaths(job, new Path(SysUtil.inputPath(CASE_NAME)));
        FileOutputFormat.setOutputPath(job, new Path(SysUtil.outputPath(CASE_NAME)));
        //7 提交 Job
        boolean b = job.waitForCompletion(true);
        System.exit(b ? 0 : 1);



    }
}
